#ifndef _COMPACT_WIFI_BOARD_CAM_H_
#define _COMPACT_WIFI_BOARD_CAM_H_

#include <string>
#include <stdbool.h>
#include <stdint.h>
#include "esp_camera.h"
#include "boards/common/wifi_board.h"
#include "boards/common/camera.h"
#include "config.h" // 包含配置文件，使用其中的GPIO定义

// 补充缺少的相机引脚定义
#define CAMERA_PIN_HREF     GPIO_NUM_23
#define CAMERA_PIN_PCLK     GPIO_NUM_22

class Esp32Camera : public Camera {
private:
    bool initialized_;
    std::string explain_url_;
    std::string explain_token_;
    
public:
    Esp32Camera();
    virtual ~Esp32Camera();
    
    bool Initialize();
    void Deinitialize();
    
    virtual void SetExplainUrl(const std::string& url, const std::string& token) override;
    virtual bool Capture() override;
    virtual bool SetHMirror(bool enabled) override;
    virtual bool SetVFlip(bool enabled) override;
    virtual std::string Explain(const std::string& question) override;
};

class CompactWifiBoard : public WifiBoard {
private:
    Esp32Camera* camera_;
    bool camera_initialized_;
    
public:
    CompactWifiBoard();
    virtual ~CompactWifiBoard();
    
    // 从基类继承的方法，需要使用 override 关键字
    virtual std::string GetBoardType() override;
    virtual Camera* GetCamera() override;
    virtual AudioCodec* GetAudioCodec() override;
    virtual std::string GetDeviceStatusJson() override;
    virtual bool GetBatteryLevel(int &level, bool& charging, bool& discharging) override;
    
    // 自定义方法，不需要 override 关键字
    bool Initialize();
    void Deinitialize();
    const char* GetName();
    bool HasCamera();
    bool HasDisplay();
    bool IsButtonPressed();
    void ToggleLed();
    void SetLed(bool on);
};

// Board initialization and cleanup functions
bool board_init();
void board_deinit();

// Hardware feature query
const char *board_get_name();
bool board_has_camera();
bool board_has_display();

// LED control
void board_led_toggle();
void board_led_set(bool on);

// Button detection
bool board_button_pressed();

// Sensor data
float board_get_battery_level();
float board_get_temperature();

// Camera functions
bool camera_init();
void camera_deinit();
camera_fb_t *camera_capture();
void camera_fb_free(camera_fb_t *fb);

#endif // _COMPACT_WIFI_BOARD_CAM_H_